const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');

const PointRule = sequelize.define('PointRule', {
  id: {
    type: DataTypes.UUID,
    defaultValue: DataTypes.UUIDV4,
    primaryKey: true
  },
  name: {
    type: DataTypes.STRING,
    allowNull: false,
    comment: '积分规则名称'
  },
  type: {
    type: DataTypes.ENUM('earn', 'spend'),
    allowNull: false,
    comment: '积分规则类型'
  },
  points: {
    type: DataTypes.INTEGER,
    allowNull: false,
    comment: '积分数量'
  },
  conditions: {
    type: DataTypes.JSON,
    defaultValue: {},
    comment: '积分规则条件'
  },
  status: {
    type: DataTypes.ENUM('active', 'inactive'),
    defaultValue: 'active',
    comment: '积分规则状态'
  },
  description: {
    type: DataTypes.TEXT,
    comment: '积分规则描述'
  },
  valid_from: {
    type: DataTypes.DATE,
    comment: '积分规则有效期开始时间'
  },
  valid_to: {
    type: DataTypes.DATE,
    comment: '积分规则有效期结束时间'
  },
  daily_limit: {
    type: DataTypes.INTEGER,
    comment: '每日积分上限'
  },
  monthly_limit: {
    type: DataTypes.INTEGER,
    comment: '每月积分上限'
  },
  metadata: {
    type: DataTypes.JSON,
    defaultValue: {},
    comment: '元数据'
  }
}, {
  underscored: true,
  comment: '积分规则信息表'
});

module.exports = PointRule; 